using System;

namespace ReactiveChannelMessaging.WinForms;

/// <summary>
/// Modbus报文解析结果，用于存储格式化的解析信息
/// </summary>
public class ModbusParseResult
{
    /// <summary>
    /// 功能码
    /// </summary>
    public string FunctionCode { get; set; }
    
    /// <summary>
    /// 类型（请求/响应）
    /// </summary>
    public string Type { get; set; }
    
    /// <summary>
    /// 标准格式
    /// </summary>
    public string StandardFormat { get; set; }
    
    /// <summary>
    /// 当前实现
    /// </summary>
    public string CurrentImplementation { get; set; }
    
    /// <summary>
    /// 状态
    /// </summary>
    public string Status { get; set; }
    public object RespondObject { get; set; }

    public ModbusParseResult(string functionCode, string type, string standardFormat, string currentImplementation, string status, object _RespDataStatus)
    {
        FunctionCode = functionCode ?? throw new ArgumentNullException(nameof(functionCode));
        Type = type ?? throw new ArgumentNullException(nameof(type));
        StandardFormat = standardFormat ?? throw new ArgumentNullException(nameof(standardFormat));
        CurrentImplementation = currentImplementation ?? throw new ArgumentNullException(nameof(currentImplementation));
        Status = status ?? throw new ArgumentNullException(nameof(status));
        RespondObject = _RespDataStatus;
    }

    /// <summary>
    /// 返回表格形式的字符串表示
    /// </summary>
    /// <returns>表格形式的字符串</returns>
    public override string ToString()
    {
        return $"| {FunctionCode} | {Type} | {StandardFormat} | {CurrentImplementation} | {Status} |";
    }

    /// <summary>
    /// 返回表格头部
    /// </summary>
    /// <returns>表格头部字符串</returns>
    public static string GetTableHeader()
    {
        return "| 功能码 | 类型 | 您的标准格式 | 当前实现 | 状态 |\n" +
               "|--------|------|------------|----------|------|";
    }
}